package com.lt.test.consumer.web.util;

import net.sf.json.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class WeChatUtil {
	public static final String APPID = "wx65b4d24b9948e48c";
	public static final String APPSECRET = "714a8a1ce3434cc5fc08176b07ef3b62";
	public static final String MCHID="1505594701";
	public static final String SPBILLIP="10.92.60.86";
//	public static final String SSLCERT_PATH="D:\\develop\\wxpay\\apiclient_cert.p12";
	public static final String SSLCERT_PATH="/home/app_01/consumer/weixinsercret/mynameisok.p12";

	
	// url 接口地址
	public static JSONObject getJSONObject(String url) throws ClientProtocolException, IOException {
		JSONObject jsonObject = null;
		// 初始化DefaultHttpClient 对象
		DefaultHttpClient client = new DefaultHttpClient();
		/**
		 * 通过get方式提交 使用HTTPget并传入url地址
		 */
		HttpGet httpGet = new HttpGet(url);
		// execute发送请求
		HttpResponse execute = client.execute(httpGet);
		// 返回结果集
		HttpEntity entity = execute.getEntity();
		// 返回的结果不为空
		if (entity != null) {
			// 转换为String
			String string = EntityUtils.toString(entity, "UTF-8");
			// 转换为json格式
			jsonObject = JSONObject.fromObject(string);
		}
		// 关闭链接
		httpGet.releaseConnection();
		return jsonObject;
	}
}
